Imports Microsoft.VisualBasic
Imports System

<Serializable()> _
Public Class Base

    Private _id As Integer
    Private _name As String
    Private _desc As String
    Private _setup As BaseSetup

    Public Sub New(ByVal id As Integer, ByVal name As String, ByVal desc As String)

        _id = id
        _name = name
        _desc = desc

    End Sub


    Public Property ID() As Integer
        Get
            Return _id
        End Get
        Set(ByVal value As Integer)
            _id = value
        End Set
    End Property

    Public Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property

    Public Property Desc() As String
        Get
            Return _desc
        End Get
        Set(ByVal value As String)
            _desc = value
        End Set
    End Property

    Public Property Setup() As BaseSetup
        Get
            Return _setup
        End Get
        Set(ByVal value As BaseSetup)
            _setup = value
        End Set
    End Property


    Public Function SetupToXML() As String
        Return _setup.SetupToXML()
    End Function

    Public Sub XMLToSetup(ByVal xml As String)
        _setup.XMLToSetup(xml)
    End Sub

    Public Function Clone() As Base
        Dim _clone As New Base(Me.ID, Me.Name, Me.Desc)

        _clone.Setup = _setup.Clone()

        Return _clone
    End Function

    Public Overrides Function ToString() As String
        Dim str As String = ""


        str &= "ID         :" & Me.ID & Environment.NewLine

        str &= "Name       :" & Me.Name & Environment.NewLine
        'str &= "Description: " & Me.Desc & Environment.NewLine
        str &= Setup.ToString & Environment.NewLine


        Return str

    End Function


    Public Function ValidateBase() As Collection
        Dim errList As New Collection
        Dim errRow As ErrorRow
        'contains a of rows. each row represents an error

        'validate the name

        'allow only A..Z a..z 0..9
        For Each ch As String In Name

            'not A..Z and not 0..9 and not a..z
            If ((Not (Asc(ch) >= 65 And Asc(ch) <= 90)) And (Not (Asc(ch) >= 48 And Asc(ch) <= 57)) And (Not (Asc(ch) >= 97 And Asc(ch) <= 122))) Then
                errRow = New ErrorRow
                errRow.Field = "Name"
                errRow.Value = Name
                errRow.Message = Cons.VALIDATION_ERROR_INVALID_NameValue
                errList.Add(errRow)
            End If
        Next


        'validate the description
        If (Desc.Length = 0) Then

        End If

        'validate the setup
        If (Not Setup.ValidateBaseSetup() Is Nothing) Then
            For Each _errRow As ErrorRow In Setup.ValidateBaseSetup()
                errList.Add(_errRow)
            Next
        End If
        

        'If errList.Count > 0 Then
        Return errList
        'Else
        'Return Nothing
        'End If

    End Function

End Class
